﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using CodeDDD.Application.Seedwork;

namespace CodeDDD.Presentation.MVC
{
    public abstract class BaseController : Controller
    {
        protected void AddModelValidationErrors(ApplicationValidationErrorsException exception)
        {
            foreach (var validationError in exception.ValidationErrors)
            {
                ModelState.AddModelError(string.Empty, validationError);    
            }
        }

        protected IEnumerable<string> GetErrorsFromModelState()
        {
            return ModelState.SelectMany(x => x.Value.Errors.Select(error => error.ErrorMessage));
        }
    }
}
